﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SPFeatureGenerator
{
    public class ContentType
    {
        private String featureName = null;
        private String name = null;
        private String description = null;
        private String group = null;
        private String templateName = null;
        private String templateFullName = null;
        private String typePrefix = null;

        public String FeatureName
        {
            get { return featureName; }
        }

        public String Name
        {
            get { return name; }
            set { name = value; }
        }
        
        public String Description
        {
            get { return description; }
            set { description = value; }
        }

        public String Group
        {
            get { return group; }
            set { group = value; }
        }

        public String TypePrefix
        {
            get { return typePrefix; }
            set { typePrefix = value; }
        }

        public String TemplateName
        {
            get { return templateName; }
            set { templateName = value; }
        }

        public String TemplateFullName
        {
            get { return templateFullName; }
            set { templateFullName = value; }
        }

        public ContentType(String featureName)
        {
            this.featureName = featureName;
        }

        public string toXML()
        {
            string templateXML = templateName != null ? String.Format("<DocumentTemplate TargetName=\"{0}\" />", templateName) : string.Empty;

            // ContentType
            string xml = String.Format(Utils.getResource("ContentTypeFragment.xml"),
                    getContentId(), name, description, group, templateXML);

            // Module
            xml += String.Format(Utils.getResource("ModuleFragment.xml"),
                    name, featureName, templateName);

            return xml;
        }

        private string getContentId()
        {
            return  typePrefix + Guid.NewGuid().ToString().Replace("-", string.Empty);
        }
    }
}
